package com.deercrowing.takeaway.common.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@Configuration
public class OrderIDGenerator {

    private String currentDate;

    public OrderIDGenerator() {
        this.currentDate = getCurrentDate();
    }

    public String generateID() {
        String id = currentDate;
        return id;
    }

    private String getCurrentDate() {
        // 创建一个LocalDateTime实例
        LocalDateTime currentDateTime = LocalDateTime.now();

        // 设置时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HHmmss");

        // 使用formatter格式化LocalDateTime
        String formattedDateTime = currentDateTime.format(formatter);
        return formattedDateTime;
    }
}
